package com.athuahua.spzx.exception;

import com.athuahua.spzx.utils.Result;
import com.athuahua.spzx.utils.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: huahua
 * @Date: 2024/7/21 0021
 * @Time: 12:46
 * @Description: 统一事务处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public Result error(){
//
//        return Result.build(null, ResultCodeEnum.DATA_ERROR);
//    }

    //自定义异常处理
    @ExceptionHandler(CodeException.class)
    @ResponseBody
    public Result error(CodeException e){

        return Result.build(null, e.getResultCodeEnum());
    }
}
